SpatialStream® Code Examples

Getting Legend Image

Creating an accurate and dynamic legend doesn't need to be difficult, and the functional components of Legend and Map Composition File simplify this development task. The Legend service will retrieve the layer images and names from the current Map Composition File for populating on a surface of your choosing to create a dynamic legend.

This example shows how to use the Legend and the Map Composition File components to retrieve information and images used to construct a legend showing census tract, postalcode, city, and county boundaries.

Map Composition File | Legend

//Show Legend
var list = map.DMPLayers[0].getResourceReferences();
var legendHtml = "";
for (var i in list) {

var legend = list[i].getLegendModel();
legendHtml += "<img src='" + Dmp.Env.Connections["SS"].getBaseUrl() + legend.getUrl() + "' />";
legendHtml += list[i].title + " ";
legendHtml += "<hr/>";
} //i
document.getElementById("mylegend").innerHTML = legendHtml;


Run Sample   View Video   Back To Index